/**
 * Created by 张旭东 on 2017/8/30.
 */

function testFunc() {
    var name = $("#testInput").val();
    var pwd = $("#testPwd").val();
    var realName = $("#testRealName").val();
    var sex = $("#testSex").val();
    var info = {
        name: name,
        pwd:pwd,
        realName:realName,
        sex:sex
    };

    $.ajax({
        url: './test.do',
        datatype: 'json',
        async: false,
        data: JSON.stringify(info),//数据入参
        type: 'POST',
        contentType: 'application/json;charset=UTF-8',
        success: function (message) {
            if (message.status == 'success') {
                alert("添加成功");
            } else {
                alert("操作失败：" + message.errMsg);
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert("readyState=" + XMLHttpRequest.readyState);//0 － （未初始化）还没有调用send()方法
            alert("status=" + XMLHttpRequest.status);
            alert("textStatus=" + textStatus);
        }
    })
}

function queryUser() {
    var info = {
        name: null
    };

    $.ajax({
        url: './userQuery.do',
        datatype: 'json',
        async: false,
        data: JSON.stringify(info),//数据入参
        type: 'POST',
        contentType: 'application/json;charset=UTF-8',
        success: function (message) {
            if (message.status == 'success') {
                // alert("message.data==="+message.data);
                var data = message.data;
                var html = '<tr><td>序号</td><td>用户名</td><td>真实姓名</td><td>性别</td><td>注册时间</td></tr>';
                for (var i = 0; i < data.length; i++) {
                    html+='<tr><td>'+(i+1)+'</td><td>'+data[i].name+'</td><td>'+data[i].realName+'</td><td>'+data[i].sex+'</td><td>'+data[i].crtDate+'</td></tr>'
                }
                $('#userList').empty();
                $('#userList').append(html);
            } else {
                alert("操作失败：" + message.errMsg);
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert("readyState=" + XMLHttpRequest.readyState);//0 － （未初始化）还没有调用send()方法
            alert("status=" + XMLHttpRequest.status);
            alert("textStatus=" + textStatus);
        }
    })
}
